package com.iye.puretennis.custom;

import android.app.ActionBar;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import com.iye.puretennis.R;
import com.iye.puretennis.fragment.MyAppointmentFragment;

/**
 * Created with IntelliJ IDEA.
 * User: jing wu
 * Date: 2014/12/5
 * Time: 12:51
 */
public class AppointmentActionWindow extends PopupWindow {

    private ImageButton accept;


    public AppointmentActionWindow(final MyAppointmentFragment fragment) {

        super(fragment.getActivity());

        FragmentActivity fragmentActivity = fragment.getActivity();
        LayoutInflater inflater = (LayoutInflater) fragmentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mainView = inflater.inflate(R.layout.appointment_menu, null);
        this.setWidth(ActionBar.LayoutParams.MATCH_PARENT);
        this.setHeight(ActionBar.LayoutParams.WRAP_CONTENT);
        ColorDrawable dw = new ColorDrawable(0xb0000000);

        accept = (ImageButton) mainView.findViewById(R.id.accept_menu);
        final int type = fragment.getType();

        if(type == 3){
            accept.setVisibility(View.VISIBLE);
        }else{
            accept.setVisibility(View.GONE);
        }

        ImageButton delete = (ImageButton) mainView.findViewById(R.id.delete_menu);

        View.OnClickListener buttonClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int viewId = view.getId();
                if (type != -1) {
                    if (viewId == accept.getId()) {
                        fragment.accept();
                    } else {
                        fragment.remove(type);
                    }
                    dismiss();
                }
            }
        };
        accept.setOnClickListener(buttonClickListener);
        delete.setOnClickListener(buttonClickListener);


        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        this.setContentView(mainView);
        this.setFocusable(true);
    }
}
